package online.longzipeng.back.controller;

import online.longzipeng.back.pojo.Result;
import online.longzipeng.back.pojo.entity.Bill;
import online.longzipeng.back.pojo.param.BillQueryParam;
import online.longzipeng.back.pojo.param.PageParam;
import online.longzipeng.back.pojo.vo.BillVo;
import online.longzipeng.back.service.BillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 账单控制层
 *
 * @author lzp
 */
@RestController
@RequestMapping("/bill")
public class BillController {

    @Autowired
    private BillService billService;


    /**
     * 查询账单详情
     */
    @GetMapping("/detail")
    public Result<BillVo> detail(@RequestParam(value = "id", required = true) Long id) {
        return Result.success(billService.detail(id));
    }

    /**
     * 账单分页查询
     */
    @PostMapping("/page")
    public Result page(@RequestBody PageParam<BillQueryParam> param) {
        return Result.success(billService.page(param));
    }

    /**
     * 新增或保存账单
     */
    @PostMapping("/save")
    public Result save(@RequestBody Bill bill) {
        billService.save(bill);
        return Result.success();
    }

    /**
     * 删除账单【单个】
     */
    @GetMapping("/delete/one")
    public Result deleteOne(Long id) {
        billService.deleteOne(id);
        return Result.success();
    }

    /**
     * 删除账单【多个】
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody List<Long> ids) {
        billService.delete(ids);
        return Result.success();
    }

}
